package com.wthink.newMain.login

import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.view.WindowManager
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.wthink.hzgj.R
import com.wthink.hzgj.databinding.ActivityLoginBinding
import com.wthink.hzgj.util.toast
import com.wthink.newMain.settings.MenuActivity
import kotlinx.android.synthetic.main.activity_login.*

class LoginActivity : AppCompatActivity() {

    lateinit var binding: ActivityLoginBinding
    private val viewModel by viewModels<LoginViewModel>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_login)
        binding.lifecycleOwner = this
        binding.viewModel = viewModel

        binding.back.setOnClickListener {
            finish()
        }

        binding.btnLogin.setOnClickListener {

          /*  val intent = Intent(this, MenuActivity::class.java)
            finish()
            startActivity(intent)*/

            val admin = et_admin.text.toString()
            val pwd = et_pwd.text.toString()
            if (TextUtils.isEmpty(admin) || TextUtils.isEmpty(pwd)) {
                toast(
                    this, "请输入用户名密码"
                )
                return@setOnClickListener
            }

/*            if (admin == "admin" && pwd == "123456") {
                val intent = Intent(this, MenuActivity::class.java)
                finish()
                startActivity(intent)
            } else {
                toast(
                    this, "用户名密码错误"
                )
            }*/
            viewModel.login(admin,pwd) {
                val intent = Intent(this, MenuActivity::class.java)
                finish()
                startActivity(intent)
            }
        }
    }
}